<div class="container">    
	<div class="row">                    
		<div class="panel panel-info">
			<div class="panel-heading">
				<div class="panel-title">Search Result</div>
			</div>
			<div class="panel-body">
				<?php if(isset($searchresult['error'])):?>
				<div class="alert alert-danger alert-dismissable">
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<?php echo $searchresult['error']; ?>
				</div>
				<?php endif;?>
				<?php if(isset($searchresult['api'])){?>
				<div class="well well-sm">
					<div class="row">
						<div class="col-md-6">
							<h3><?=$searchresult['api']['RRPText']?></h3>
							<h1><?=$searchresult['api']['DomainName']?></h1>
						</div>
						<div class="col-md-6 text-right">
							<?php if($searchresult['api']['RRPText']=="Domain available"){
							$tld=substr($searchresult['api']['DomainName'],strpos($searchresult['api']['DomainName'], '.')+1);
							$sld=substr($searchresult['api']['DomainName'],0,strpos($searchresult['api']['DomainName'], '.'));
							
							//print_r($sld);
							?>
							<h3>Only $<?=$searchresult['api']['price']?></h3>
							<button type="button" class="btn btn-primary btn-lg" onclick="addtocart('<?=$sld?>','<?=$tld?>',this);">Add</button>
							<?}else{?>
							<button type="button" class="btn btn-danger btn-lg" style="margin-top:35px;">Taken</button>
							<?}?>
						</div>
					</div>
				</div>
				<?}?>
				<div class="row relativedomain">
				</div>
				<div class="row">
					<div class="col-md-12">
						<ul class="nav nav-tabs" role="tablist">
							<li class="active"><a href="#results" role="tab" data-toggle="tab">Results</a></li>
							<li><a href="#newdomain" role="tab" data-toggle="tab">New Domain</a></li>
							<li><a href="#international" role="tab" data-toggle="tab">International</a></li>
						</ul>
						<!-- Tab panes -->
						<div class="tab-content">
							<div class="tab-pane active" id="results">
								<div class="row">
									<div class="col-md-6">
										<h3>Suggested</h3>
										
										<table class="table">
											<tbody class="suggested_domain">
												<tr>
													<td colspan="2"></td>
												</tr>
											</tbody>
										</table>
									</div>
									<div class="col-md-6">
										<h3>Premium</h3>
										<table class="table">
											<tbody class="premium_domain">
											
												<tr>
													<td colspan="2"></td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
								<div class="row">
									<div class="col-md-12">
										<h3>More Domain Names</h3>
										<table class="table">
											<tbody class="moredomain">
												
												<tr>
													<td colspan="2"></td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
							<div class="tab-pane" id="newdomain">
								<table class="table">
									<tbody class="newdomain">
										
										<tr>
											<td colspan="2"></td>
										</tr>
									</tbody>
								</table>
							</div>
							<div class="tab-pane" id="international">
								<table class="table">
									<tbody class="internationaldomain">
										
										<tr>
											<td colspan="2"></td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
				
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	$.ajax({
		url: '<?php echo base_url('enom/check');?>',
		dataType: 'jsonp',
		method:'post',
		data:{url:'<?=$searchresult['relativedomainurl']?>'},
		beforeSend: function() {
			$('.relativedomain').html('<div class="col-md-12 text-center wait" style="height:156px;">'+
					'<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" />'+
					'</div>');
		},		
		complete: function() {
			$('.wait').remove();
		},			
		success: function(json) {
			html="";
			newdomain=['ninja','social','xyz','supplies','club'];
			if (json['result']['api'] != '') {
				for (i = 0; i < json['result']['api']['Domain'].length; i++) 
				{
					if($.inArray(json['result']['api']['tld'][i],newdomain)>-1)
					{
						newclass='new';
					}
					else
					{
						newclass='';
					}
					
					html+='<div class="col-md-1-5 ">';
					html+=	'<div class="panel panel-default '+newclass+'">';
					html+=		'<div class="panel-body text-center">';	
					html+=			'<h4>'+ json['result']['api']['tld'][i]+'</h4>';
					html+=			'<span> $'+ json['result']['api']['price'][i]+'</span>';
					html+=		'</div>';
					if(json['result']['api']['RRPText'][i]=="Domain available"){
					html+=		'<a href="javascript:void(0)" class="searcha" onclick="addtocart(\''+json['result']['api']['sld'][i]+'\',\''+json['result']['api']['tld'][i]+'\',this)">';
					html+=			'<div class="panel-footer blue text-center"><span>Add</span></div>';
					}else{
					html+=		'<a class="searcha disable">';
					html+=			'<div class="panel-footer disablecolor text-center"><span>Taken</span></div>';
					}
					html+=		'</a>';
					html+=	'</div>';
					html+='</div>';
				}
			}
			$('.relativedomain').html(html);
		}
	});
	/*suggested Domain*/
	$.ajax({
		url: '<?php echo base_url('enom/namespinner');?>',
		dataType: 'json',
		method:'post',
		data:{url:'<?=$searchresult['suggestedurl']?>'},
		beforeSend: function() {
			$('.suggested_domain').prepend('<div class="col-md-12 text-center wait1" style="height:156px;">'+
					'<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" />'+
					'</div>');
		},		
		complete: function() {
			$('.wait1').remove();
		},			
		success: function(json) {
			html="";
			if (json['result']['api'] != '') 
			{
				for (i = 0; i < json['result']['api']['namespin']['domains']['domain'].length; i++) 
				{
					//alert(json['result']['api']['namespin']['domains']['domain'][i]);
					html+='<tr>';
					html+=	'<td><strong>'+json['result']['api']['namespin']['domains']['domain'][i]['domain_name']+'</strong></td>';
					html+=	'<td align="right"><span class="price"> $'+json['result']['api']['namespin']['domains']['domain'][i]['price']+'</span><button type="button" class="btn btn-primary">Add</button></td>';
					html+='</tr>';
				}
			}
			$('.suggested_domain').prepend(html);
			
		}
	});
	/*premium_domain*/
	$.ajax({
		url: '<?php echo base_url('enom/premium');?>',
		dataType: 'json',
		method:'post',
		
		beforeSend: function() {
			$('.premium_domain').prepend('<div class="col-md-12 text-center wait2" style="height:156px;">'+
					'<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" />'+
					'</div>');
		},		
		complete: function() {
			$('.wait2').remove();
		},			
		success: function(json) {
			html="";
			if (json['result'] != '') 
			{
				html+=json['result'];
				
			}
			$('.premium_domain').prepend(html);
			
		}
	});
	/*more Domain*/
	$.ajax({
		url: '<?php echo base_url('enom/moredomain');?>',
		dataType: 'json',
		method:'post',
		data:{url:'<?=$searchresult['moredomainurl']?>'},
		beforeSend: function() {
			$('.moredomain').prepend('<div class="col-md-12 text-center wait3" style="height:156px;">'+
					'<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" />'+
					'</div>');
		},		
		complete: function() {
			$('.wait3').remove();
		},			
		success: function(json) {
			html="";
			if (json['result']['api'] != '') 
			{
				for (i = 0; i < json['result']['api']['Domain'].length; i++) 
				{
					//alert(json['result']['api']['namespin']['domains']['domain'][i]);
					html+='<tr>';
					html+=	'<td><strong>'+json['result']['api']['Domain'][i]+'</strong></td>';
					html+=	'<td align="right"><span class="price"> $'+json['result']['api']['price'][i]+'</span><button type="button" class="btn btn-primary">Add</button></td>';
					html+='</tr>';
				}
			}
			$('.moredomain').prepend(html);
			
		}
	});
	
	/*New Domain*/
	$.ajax({
		url: '<?php echo base_url('enom/newdomain');?>',
		dataType: 'json',
		method:'post',
		data:{url:'<?=$searchresult['moredomainurl']?>'},
		beforeSend: function() {
			$('.newdomain').prepend('<div class="col-md-12 text-center wait4" style="height:156px;">'+
					'<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" />'+
					'</div>');
		},		
		complete: function() {
			$('.wait4').remove();
		},			
		success: function(json) {
			html="";
			if (json['result']['api'] != '') 
			{
				for (i = 0; i < json['result']['api']['Domain'].length; i++) 
				{
					//alert(json['result']['api']['namespin']['domains']['domain'][i]);
					html+='<tr>';
					html+=	'<td><strong>'+json['result']['api']['Domain'][i]+'</strong></td>';
					html+=	'<td align="right"><span class="price"> $'+json['result']['api']['price'][i]+'</span><button type="button" class="btn btn-primary">Add</button></td>';
					html+='</tr>';
				}
			}
			$('.newdomain').prepend(html);
			
		}
	});
	
	/*International Domain*/
	$.ajax({
		url: '<?php echo base_url('enom/internationaldomain');?>',
		dataType: 'json',
		method:'post',
		data:{url:'<?=$searchresult['moredomainurl']?>'},
		beforeSend: function() {
			$('.internationaldomain').prepend('<div class="col-md-12 text-center wait5" style="height:156px;">'+
					'<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" />'+
					'</div>');
		},		
		complete: function() {
			$('.wait5').remove();
		},			
		success: function(json) {
			html="";
			if (json['result']['api'] != '') 
			{
				for (i = 0; i < json['result']['api']['Domain'].length; i++) 
				{
					//alert(json['result']['api']['namespin']['domains']['domain'][i]);
					html+='<tr>';
					html+=	'<td><strong>'+json['result']['api']['Domain'][i]+'</strong></td>';
					html+=	'<td align="right"><span class="price"> $'+json['result']['api']['price'][i]+'</span><button type="button" class="btn btn-primary">Add</button></td>';
					html+='</tr>';
				}
			}
			$('.internationaldomain').prepend(html);
			
		}
	});
	
});
function addtocart(sld,tld,e)
{
	$.ajax({
		url: '<?php echo base_url('enom/addtocart');?>',
		type: 'post',
		data: 'sld=' + sld + '&tld=' + tld + '&product_id=10' + '&product_type=Register' ,
		dataType: 'json',
		beforeSend: function() {
			$(e).text('checking..');
			$(e).children('.blue').children('span').text('checking..');
		},		
		complete: function() {
			$(e).text('checkout');
			$(e).children('.blue').css('background','#F9B014');
			$(e).children('.blue').children('span').text('checkout');
		},
		success: function(json) {
			if(json['message'])
			{
				$('#ajax_msg').html('<div class="alert alert-success alert-dismissable flashmsg"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+ json['message'] + '</div>');
				$('#ajax_msg .flashmsg').delay(5000).fadeOut('slow');
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
			}
			$.get('<?php echo base_url('enom/viewcart');?>', function(cart){
  				$(".cart_content").html(cart);
			});
		}
	});
}
</script>
